$OpenBSD: patch-src_tools_qfile_cpp,v 1.3 2007/03/31 22:49:46 espie Exp $
--- src/tools/qfile.cpp.orig	Thu Oct 19 16:25:01 2006
+++ src/tools/qfile.cpp	Sat Mar 31 14:51:25 2007
@@ -70,8 +70,13 @@ class QFilePrivate
 {
 public:
     QString errorString;
+    int lastAccess;
 };
 
+#define ACCESS_NONE -1
+#define ACCESS_READ 0
+#define ACCESS_WRITE 1
+
 extern bool qt_file_access( const QString& fn, int t );
 
 /*!
@@ -196,6 +201,7 @@ void QFile::init()
 {
     delete d;
     d = new QFilePrivate;
+    d->lastAccess = ACCESS_NONE;
     setFlags( IO_Direct );
     setStatus( IO_Ok );
     setErrorString( qt_fileerr_unknown );
@@ -206,7 +212,6 @@ void QFile::init()
     ext_f  = FALSE;				// not an external file handle
 }
 
-
 /*!
     \fn QString QFile::name() const
 
@@ -382,6 +387,10 @@ Q_LONG QFile::readLine( char *p, Q_ULONG maxlen )
     if ( isRaw() ) {				// raw file
 	nread = QIODevice::readLine( p, maxlen );
     } else {					// buffered file
+    	if (d->lastAccess == ACCESS_WRITE) {
+	    ::fseek(fh, 0, SEEK_CUR);
+	    d->lastAccess = ACCESS_READ;
+	}
 	p = fgets( p, maxlen, fh );
 	if ( p ) {
 	    nread = qstrlen( p );
@@ -463,6 +472,10 @@ int QFile::getch()
 	char buf[1];
 	ch = readBlock( buf, 1 ) == 1 ? buf[0] : EOF;
     } else {					// buffered file
+    	if (d->lastAccess == ACCESS_WRITE) {
+	    ::fseek(fh, 0, SEEK_CUR);
+	    d->lastAccess = ACCESS_READ;
+	}
 	if ( (ch = getc( fh )) != EOF ) {
 	    if ( !isSequentialAccess() )
 		ioIndex++;
@@ -499,6 +512,10 @@ int QFile::putch( int ch )
 	buf[0] = ch;
 	ch = writeBlock( buf, 1 ) == 1 ? ch : EOF;
     } else {					// buffered file
+    	if (d->lastAccess == ACCESS_READ) {
+	    ::fseek(fh, 0, SEEK_CUR);
+	    d->lastAccess = ACCESS_WRITE;
+	}
 	if ( (ch = putc( ch, fh )) != EOF ) {
 	    if ( !isSequentialAccess() )
 		ioIndex++;
@@ -553,6 +570,10 @@ int QFile::ungetch( int ch )
 	else
 	    ch = EOF;
     } else {					// buffered file
+    	if (d->lastAccess == ACCESS_WRITE) {
+	    ::fseek(fh, 0, SEEK_CUR);
+	    d->lastAccess = ACCESS_READ;
+	}
 	if ( (ch = ungetc(ch, fh)) != EOF ) {
 	    if ( !isSequentialAccess() )
 		ioIndex--;
